<?php
/**
 * Qrcode_model 扫描二维码进入网站统计
 * @author  yw 
 * 2017年6月6日17:36:24
 */

class Qrcode_model extends BS_Model
{

	/**
	 * [add 添加一条记录]
	 * @param array $params [受影响的行数]
	 */
	public function add($params = array())
	{
		if(!is_array($params)) return;
		$query = $this->db->from('qrcode')->where('location_id',$params['location_id'])->get();
		if($query->row_array()>0){
			$sql = "update qrcode set update_time = '".$params['update_time']."',number=number+1 where location_id='".$params['location_id']."'";
			return $this->db->query($sql);
		}
		return $this->db->insert('qrcode',$params);
	}

	/**
	 * [getCountByQuery 统计]
	 * @return [array] 
	 */
	public function getCountByQuery()
	{
		$this->db->from('qrcode as A');
		$this->db->select('A.id,B.location_name,A.number,A.update_time');
		$this->db->group_by('A.location_id');
		$this->db->join('location AS B','A.location_id = B.id','LEFT');
		$this->db->order_by('A.number DESC');
		$query = $this->db->get();
		return $query->num_rows()>0 ? $query->result_array() : array();
	}

	/**
	 * [delQrcodeById 删除一条记录] 预留
	 * @param $id 地址id 
	 * @return [type] [description]
	 */
	public function delQrcodeById($id)
	{}
}